<template>
	<div>
		<!-- 这里是ODD -->

		<van-cell :title="title" is-link @click="toCreateOdd" class="cell_header_title" />
		<van-cell :title="title_" />

		<!-- <div v-for="item in pending">
			
			
			
		</div> -->
		
		<van-empty v-if="pending.length==0" description="当前没有要处理的订单" />

		<div class="item" v-for="odd in pending" 
		v-bind:class="[odd.in_or_out?'in':'out']" @click="toDetail(odd.id)">


			<div>{{odd.in_or_out?'入库单':'出库单'}}</div>
			<div class="item_">订单编号: {{odd.id}}</div>
			<div class="item_">库房: {{odd.warehouse_name}}</div>
			<div class="item_">来往单位: {{odd.subject_name}}</div>
			<div class="item_">订单创建人员: {{odd.sponsor}}</div>
			<div class="item_">订单操作人员: {{odd.operator!=null?odd.operator: '等待接单'}}</div>
			<div></div>
			<div class="item_">时间: {{getLocalTime(odd.create_time)}}</div>
			<div class="remark">用途备注: {{odd.remark}}</div>
			
			<!-- <van-button type="primary">接单</van-button> -->
			
		</div>
		
		<div style="height: 140px;"></div>
		



	</div>
</template>

<script>
	import Cookies from 'js-cookie'
	import {
		Toast
	} from 'vant'
	import {
		get_all_odd
	} from "../../utils/get_all_odd.js"
	import {
		get_odd_detail
	} from "../../utils/get_all_odd.js"
	export default {
		name: '',
		components: {},
		props: {},
		data() {
			return {
				title: '创建新的入库单',
				title_: '当前待处理订单',
				pending: [],
				router_name: '',
				in_or_out: null,
			}
		},
		methods: {
			
			getLocalTime(nS) {
			   return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');     
			},
			//跳转至添加新订单页面
			toCreateOdd() {

				this.$router.push({
					name: this.router_name
				})

			},
			
			toDetail(odd_id){
				
				this.$router.push(
					{
						name: 'OddDetail',
						query:{odd_id: odd_id}
					}
				)
				
			},

			get_all_odd_callback(res) {


				for (let i = 0; i < res.length; i++) {
					let val = res[i]
					if (val.status == 'wait' && val.operator_id == Cookies.get('user_id')) {

						this.pending = []
						this.pending.push(val)
						
						return
					}
					
					if (val.status == 'wait' && val.in_or_out == this.in_or_out) {
						this.pending.push(val)
					}
				}

				// console.log(this.pending)

			},

			
		},
		computed: {

		},
		watch: {},
		created() {},
		mounted() {

			// let query = this.$route.params
			let query = this.$route.query.in_or_out
			// console.log(query)
			if (query == 'in') {
				this.title = '创建新的入库单'
				this.router_name = 'PutInStorage'
				this.in_or_out = true
			} else if (query == 'out') {
				this.title = '创建新的出库单'
				this.router_name = 'PutOutStorage'
				this.in_or_out = false
			} else {

				Toast('非法进行入')
				this.$router.push('/')

			}

			get_all_odd(this.get_all_odd_callback)


		},
	}
</script>

<style scoped lang="less">
	.cell_header_title {
		background-color: #F0F0F0;
		font-weight: 800;
	}

	.item {
		background-color: #F0F0F0;
		margin: 5px;
		overflow: hidden;
		  *zoom: 1;

		.item_ {
			display: inline-block;
			margin: 5px;
			position: relative;
		}

		.remark {
			display: block;
			color: blue;
		}
		
		.van-button{
			display: block;
			width: 30%;
			float: right;
			// margin: 0 auto;
		}
		
		
	}
	

	.in {
		background-color: #F0F0F0;
	}

	.out {
		background-color: #F0C78A;
		// color: white;
	}
</style>
